home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / cpu / tms32010 / dis32010.c < prev    next >
C/C++ Source or Header  |  1999-01-26  |  3KB  |  90 lines

  1. /****************************************************************************
  2.  *                Texas Instruments TMS320C10 DSP Disassembler              *
  3.  *                                                                          *
  4.  *                      Copyright (C) 1999 by Quench                        *
  5.  *       You are not allowed to distribute this software commercially.      *
  6.  *                      Written for the MAME project.                       *
  7.  *                                                                          *
  8.  *     Note: Data is expected to be read from source file as MSB first.     *
  9.  *           This is a word based microcontroller.                          *
  10.  *                                                                          *
  11.  ****************************************************************************/
  12.  
  13. #include <stdio.h>
  14. #include <string.h>
  15.  
  16. #include "32010dsm.c"
  17.  
  18. int main(int argc,char *argv[])
  19. {
  20.   FILE *F;
  21.   byte *Buf;
  22.   long Counter=0;
  23.   int  len=0, lentodump=0, offset=0, disasm_bytes=0;
  24.   int  filelength=0, bytesread;
  25.   char S[87];
  26.  
  27.   if(argc<2)
  28.   {
  29.       puts("TMS32010 Disassembler 1.0 by Quench (C)1998");
  30.       puts("Note : Data is expected to be read from source file as MSB first.");
  31.       puts("Usage: dis32010 <input file> [ <start-addr> [ <num-of-opcodes> ] ]");
  32.       exit(0);
  33.   }
  34.  
  35.   if(!(F=fopen(argv[1],"rb"))) {
  36.       printf("\n%s: Can't open file %s\n",argv[0],argv[1]);exit(1);
  37.   }
  38.   argv++; argc--;
  39.   if (argv[1]) {
  40.       offset = strtol(argv[1],NULL,0);
  41.       argv++; argc--;
  42.   }
  43.   if (argv[1]) {
  44.       len = strtol(argv[1],NULL,0);
  45.       argv++; argc--;
  46.   }
  47.   len*=2;
  48.   filelength = fseek(F,0, SEEK_END);
  49.   filelength = ftell(F);
  50.   if ((len > (filelength - (offset*2))) || (len == 0)) len = filelength - (offset*2);
  51.   lentodump = len;
  52.   printf("Starting from %d, dumping %d opcodes (word size)\n",offset,(len/2));
  53.   Buf=calloc((len+3),sizeof(char));
  54.   if (Buf==NULL){
  55.       printf("Out of Memory !!!");
  56.       fclose(F);
  57.       exit(1);
  58.   }
  59.  
  60.   if (fseek(F,offset*2,0) != 0) {
  61.       fprintf(stderr,"Error seeking to offset %d\n",offset);
  62.       free(Buf);
  63.       fclose(F);
  64.       exit(1);
  65.   }
  66.   Counter = offset;
  67.   bytesread = fread(Buf,1,len+2,F);
  68.   if (bytesread >= len) {
  69.       for (; len > 0; len -= disasm_bytes) {
  70.          int ii;
  71.          disasm_bytes = Dasm32010(S,Buf);
  72.          printf("%04lX: ", Counter);
  73.          Counter+=disasm_bytes;
  74.          disasm_bytes *= 2;
  75.          for (ii = 0; ii < disasm_bytes; ii+=2) {
  76.              printf("%02.2x%02.2x ",Buf[ii],Buf[ii+1]);
  77.          }
  78.          for (; ii < 4; ii++) { printf("   "); }
  79.          printf("\t%s\n",S);
  80.          Buf += disasm_bytes;
  81.       }
  82.   }
  83.   else {
  84.         printf("ERROR length to dump was %d ", lentodump/2);
  85.         printf(", but bytes read from file were %d\n", bytesread/2);
  86.         free(Buf);fclose(F);exit(1);
  87.   }
  88.   free(Buf);fclose(F);return(0);
  89. }
  90.